<template>
    <!-- 修改资料 -->

    <div>
        <!-- 内容主题区域 -->
        <el-form label-width="85px" :model="form" label-position="right" ref="formRef" :rules="formRules">
            <el-form-item label="编号" prop="number">
                <el-input v-model="form.number"></el-input>
            </el-form-item>
            <el-form-item label="名称" prop="name">
                <el-input v-model="form.name"></el-input>
            </el-form-item>
            <el-form-item label="角色类型" prop="roleKind">
                <el-select v-model="form.roleType" clearable placeholder="请选择：">
                    <el-option v-for="item in configData.roleTypeList" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="状态" prop="status">
                <el-switch v-model="form.status" size="large" inline-prompt :active-icon="Check" :inactive-icon="Close"
                    active-value="normal" inactive-value="disable" />
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark"></el-input>
            </el-form-item>
        </el-form>
        <!-- 底部按钮区域 -->
        <div class="button-position">
            <el-button @click="updateVisible">取 消</el-button>
            <el-button type="primary" @click="updateRole(formRef)">确 定</el-button>
        </div>
    </div>
</template>

<script setup>
import { reactive, ref, getCurrentInstance, watch, onMounted, nextTick } from 'vue';
import { ElNotification } from 'element-plus';
import { FullScreen, CopyDocument } from '@element-plus/icons-vue'
import Api from '@/api/model/user'

const emit = defineEmits(['updatetable'])

const props = defineProps({
    paramsData: {
        type: Object,
        defalut: {}
    }
})
const form = ref({
});

const formRef = ref()
const formRules = reactive({
})
const configData = ref([])
onMounted(() => {
    getInit()
})

const getInit = async () => {
    let res = await Api.optRole.detail.post(props.paramsData)
    console.log(res)
    configData.value = res.configData
    form.value = res.data
}

// 添加用户数据的对象

const updateVisible = () => {
    emit('updatetable')
}



const restAddFormData = () => {
    formRef.value.resetFields();
}



// 上传
const updateRole = async (formRef) => {
    await formRef.validate((valid, fields) => {
        if (valid) {
            updateRoleData();
        }
    })
}

const updateRoleData = async () => {
    var params = {
        bean: form.value,
    }
    var res = await Api.optRole.update.post(params);
    if (res.code == 200) {
        restAddFormData();
        ElNotification.success({ title: '', message: '添加成功！', duration: 2000 });
        emit('updatetable', true)
    }
}

</script>

<style lang="scss" scoped></style>

